<template>
	<view class="cart_content">
        <view class="cart_header">
            <salesHeader @getKh="getKh">
                <template v-slot:right_btn>
                    <view class="header_top_right" @click="scan">
                        <text class="iconfont icon-saoma"></text>
                    </view>
                </template>
            </salesHeader>
        </view>

        <view style="flex: 1; overflow: auto;">
            <shopCart @childPlacOrder="childPlacOrder" ></shopCart>
        </view>
	</view>
</template>

<script>
import customHeader from "@/components/custom-header/custom-header.vue";
import shopCart from "@/components/shop-cart/shop-cart.vue";
import salesHeader from "@/components/sales-header/sales-header.vue";
import { mapState } from 'vuex';
	export default {
		components: {
			customHeader,
            shopCart,
            salesHeader,
		},
		data() {
			return {
                khInfo: {},
			}
		},
        computed: {
            ...mapState([
                "storesCart",
            ]),
        },
		methods: {
            scan() {
                uni.scanCode({
                    onlyFromCamera: true,
                    scanType: ['qrCode', 'barCode'],
                    success: (res) => {
                        uni.navigateTo({
                            url: `../index/spDetail?huohaobh=${res.result}`
                        });
                    }
                })
            },
            childPlacOrder(param) {
                let LoginType = uni.getStorageSync('loginData').LoginType
                let list = uni.getStorageSync(`${LoginType}Cart`)
                console.log('== 缓存中数据 ', list)

                if (!Object.keys(this.khInfo).length) {
                    uni.showToast({
                        title: '请先选择客户',
                        icon: 'none'
                    });
                    return
                }

                if (!param.totalSl) {
                    uni.showToast({
                        title: '请先勾选商品',
                        icon: 'none'
                    });
                    return
                }

                let data = {
                    ...this.khInfo,
                    ...param
                }
                uni.navigateTo({
                    url: `./billing?khInfo=${JSON.stringify(data)}`
                });
                
            },
            getKh(item) {
                this.khInfo = item
            },
		},
	}
</script>

<style lang="less" scoped>
.cart_content {
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    font-size: 16rpx;

    .cart_header {
        // height: 60rpx;
        display: flex;
        align-items: center;
        padding: 15rpx 20rpx;
        border-bottom: 1rpx solid #ccc;

        .header_top_left {
            flex: 1;
            display: flex;
            align-items: center;

            .header_item {
                display: flex;
                align-items: center;
            }
        }

        .header_top_right {
            .add_btn {
                display: flex;
                align-items: center;
                height: 45rpx;
            }

            .iconfont {
                font-size: 30rpx;
                margin-right: 5rpx
            }
        }
        
    }
	
}
</style>
